package com.xuxueli.applyModules.mapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.xuxueli.applyModules.dto.S059XsZbDto;
import com.xuxueli.applyModules.entity.S059XsZbPara;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;

/**
 * 备份八大指标表
 */
@Mapper
public interface BankZbMapper {

    /**
     * 只复制表结构到新表
     */
    @Delete("CREATE TABLE IF NOT EXISTS ${tableName} SELECT * FROM ${sourceTableName} WHERE 1=2")
    void bankZbTable(@Param("tableName") String tableName, @Param("sourceTableName") String sourceTableName);

    /**
     * 复制表结构及数据到新表
     * @param tableName
     * @param sourceTableName
     */
    @Select("CREATE TABLE IF NOT EXISTS ${tableName} SELECT * FROM ${sourceTableName}")
    void bankZbTableData(@Param("tableName") String tableName, @Param("sourceTableName") String sourceTableName);

    /**
     * 是否存在主键
     */
    @Select("select count(1) from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where TABLE_NAME = #{tableName}")
    int existPkZbTable(@Param("tableName") String tableName);

    /**
     * 是否存在主键
     */
    @Select("ALTER TABLE ${tableName} ADD PRIMARY KEY(XH)")
    void createPkZbTable(@Param("tableName") String tableName);


    /**
     * 根据表名清空数据
     */
    @Delete("delete from ${tableName}")
   void deleteBankZbData(@Param("tableName") String tableName);

    /**
     * 备份指标数据
     */
    @Select("insert into ${tableName} SELECT * FROM ${sourceTableName}")
    void initBankZbData(@Param("tableName") String tableName, @Param("sourceTableName") String sourceTableName);

    /**
     * 删除存储过程
     */
    void deleteXsZbData(@Param("type") String type);

    /**
     * 创建存储过程指标数据
     */
    void createXsZbData(@Param("type") String type);

    /**
     * 执行存储过程指标数据
     */
    void callXsZbData(@Param("type") String type);

    /**
     * 分页查询
     *
     * @param page
     * @param params
     * @return
     */
    List<Map<String, Object>> pageList(Page<Map<String, Object>> page, @Param("params") Map<String, Object> params);


    /**
     * 获取所有指标数据
     */
    List<S059XsZbDto> getListZbData(@Param("s059XsZbPara") S059XsZbPara s059XsZbPara);

}

